package com.gws.juc;

import java.util.concurrent.CyclicBarrier;

/**
 * 所有线程执行完在执行
 * @author gws
 * 加
 */
public class CyclicBarrierDemo {
	
	public static void main(String[] args) {
		CyclicBarrier cyclicBarrier = new CyclicBarrier(7, () ->{System.out.println("召唤神龙");});
		for (int i = 1; i <= 7; i++) {
			final int t = i;
			new Thread(() -> {
				try {
					System.out.println(Thread.currentThread().getName()+"找到第"+t+"颗龙珠");
					cyclicBarrier.await();
				} catch (Exception e) {
					e.printStackTrace();
				}
			},String.valueOf(i)).start();
		}
	}

}
